package logic

import (
	"context"
	"doc-manage/models/mysql"

	"doc-manage/docrpc/docrpc"
	"doc-manage/docrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
	"gorm.io/gorm"
)

type DoctorAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDoctorAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DoctorAddLogic {
	return &DoctorAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *DoctorAddLogic) DoctorAdd(in *docrpc.DoctorAddRequest) (*docrpc.DoctorAddResponse, error) {
	// todo: add your logic here and delete this line
	var doctor mysql.Doctor
	doctor = mysql.Doctor{
		Model:         gorm.Model{},
		DoctorName:    in.DoctorName,
		DoctorAddress: in.DoctorAddress,
		DoctorDetail:  in.DoctorDetail,
	}
	err := doctor.DoctorAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &docrpc.DoctorAddResponse{
		DoctorId: int64(uint(in.DoctorId)),
	}, nil
}
